package org.example.algorithm.array;

public class BestTimingSolution {

    public int bestTiming(int[] prices) {
        int len = prices.length;
        if (len <= 1) {
            return 0;
        }
        int min = prices[0];
        int maxProfit = 0;
        for (int i=1;i<len;i++) {
            maxProfit = Math.max(maxProfit, prices[i]-min);
            min = Math.min(min, prices[i]);
        }
        return maxProfit;
    }
}
